package itbour.onetouchshow.activity.challengezone.video;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import com.google.gson.Gson;

import butterknife.BindView;
import itbour.onetouchshow.App;
import itbour.onetouchshow.R;
import itbour.onetouchshow.activity.challengezone.ChallengeZoneActivity;
import itbour.onetouchshow.activity.login.LoginActivity;
import itbour.onetouchshow.adapter.VideoSizeAdapter;
import itbour.onetouchshow.base.mvp.MVPBaseActivity;
import itbour.onetouchshow.bean.PersonalCreateConfigBean;
import itbour.onetouchshow.constants.DataCreater;
import itbour.onetouchshow.utils.AssetsDataUtils;
import itbour.onetouchshow.utils.L_;
import itbour.onetouchshow.utils.T_;

/**
 * Created by guoh on 2018/7/5.
 * 功能描述：选择视频尺寸
 * 需要的参数：
 */
public class ChooseVideoSizeActivity extends MVPBaseActivity<ChooseVideoSizeContract.View, ChooseVideoSizePresenter> implements ChooseVideoSizeContract.View {


    @BindView(R.id.gv_size)
    GridView gvSize;

    private VideoSizeAdapter adapter;

    @Override
    protected int getLayoutId() {
        return R.layout.ac_choose_video_size;
    }

    @Override
    protected void initTitle() {
        super.initTitle();
        setTitleText("自由创建");
    }

    @Override
    protected void afterCreate(Bundle bundle) {
        adapter = new VideoSizeAdapter(getViewContext());
        adapter.replaceAll(DataCreater.getVideoSizeConfig());
        gvSize.setAdapter(adapter);
        mPresenter.getCustomVideoConfigure();
    }

    @Override
    public void loadSucceed(String result) {
        L_.e(result);
        PersonalCreateConfigBean customVideoConfigure = new Gson().fromJson(result, PersonalCreateConfigBean.class);
        AssetsDataUtils.setCustomVideoConfigure(customVideoConfigure);
        gvSize.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (adapter.getItem(position).getVideoSize() == null) {
                    T_.showCustomToast("更多尺寸,敬请期待");
                    return;
                }
                if (App.isLogin()) {
                    startActivity(ChallengeZoneActivity.getLaunchIntent(getViewContext(), adapter.getItem(position)));
                } else {
                    openActivity(LoginActivity.class);
                }

            }
        });
    }


    @Override
    public void loadFaild(String error) {

    }


}
